// 核心类型定义
export interface StageConfig {
  id: string;
  name: string;
  duration: number;
  description: string;
  keyPoints: string[];
  animations: {
    entry: string;
    highlight: string;
    transition: string;
  };
}

export interface AnimationState {
  currentStage: number;
  isPlaying: boolean;
  playbackSpeed: number;
  currentTime: number;
  totalDuration: number;
  isTransitioning: boolean;
}

export interface ExperienceModeConfig {
  id: string;
  name: string;
  speed: number;
  showTechDetails: boolean;
  pauseAtKeyPoints?: boolean;
  includeQuizzes?: boolean;
  skipTransitions?: boolean;
  highlightMainPoints?: boolean;
  showCode?: boolean;
  showLogs?: boolean;
  allowManualInput?: boolean;
  debugMode?: boolean;
  fullscreen?: boolean;
  noControls?: boolean;
  autoplay?: boolean;
  dramaticEffects?: boolean;
}

export interface ZKProofData {
  input: {
    preImage: string;
    dataHash: string;
  };
  proof: any; // 支持动态proof结构
  public: string[];
  packedProof?: string; // ABI编码后的证明数据
  metadata?: {
    generatedAt: string;
    algorithm: string;
    curve: string;
    hashFunction: string;
    isSimulated: boolean;
  };
}

export interface BlockchainTransaction {
  txHash?: string;
  transactionHash?: string;
  contractAddress: string;
  methodName: string;
  gasUsed?: number;
  blockNumber?: number;
  status: 'pending' | 'success' | 'failed';
  timestamp?: number;
  type?: 'recordAsset' | 'verifyAssetZKPacked'; // 交易类型
  stage?: 'stage4' | 'stage5'; // 所属阶段
  verificationResult?: boolean; // 验证结果
  returnValue?: string; // 返回数据
  previousTransaction?: BlockchainTransaction; // 前一个交易记录
}

export interface ContractMethodConfig {
  name: string;
  description: string;
  prepareParams: (zkProofData: any) => any[];
}

export interface BlockchainCallResult {
  success: boolean;
  transaction?: BlockchainTransaction;
  error?: string;
}

export interface UserProgress {
  completedStages: string[];
  bookmarks: number[];
  totalWatchTime: number;
  quizScores: Record<string, number>;
  achievements: string[];
  lastVisited: number;
}

export interface PerformanceMetrics {
  frameRate: number;
  memoryUsage: number;
  loadTime: number;
  animationLag: number;
  apiLatency: number;
}

export interface AudioSettings {
  enabled: boolean;
  volume: number;
  soundEffects: boolean;
  backgroundMusic: boolean;
}

export interface VisualSettings {
  theme: 'dark' | 'light' | 'auto';
  reducedMotion: boolean;
  highContrast: boolean;
  particleCount: number;
  animationQuality: 'low' | 'medium' | 'high';
}

export interface AppState {
  // 动画状态
  animation: AnimationState;
  
  // 用户设置
  experienceMode: ExperienceModeConfig;
  audioSettings: AudioSettings;
  visualSettings: VisualSettings;
  
  // 数据状态
  zkProofData: ZKProofData | null;
  blockchainTx: BlockchainTransaction | null;
  
  // 用户进度
  userProgress: UserProgress;
  
  // 性能监控
  performance: PerformanceMetrics;
  
  // UI状态
  sidebarOpen: boolean;
  fullscreen: boolean;
  loading: boolean;
  error: string | null;
}

// 事件类型
export type AppEvent = 
  | { type: 'PLAY' }
  | { type: 'PAUSE' }
  | { type: 'RESET' }
  | { type: 'JUMP_TO_STAGE'; payload: number }
  | { type: 'SET_SPEED'; payload: number }
  | { type: 'SET_MODE'; payload: ExperienceModeConfig }
  | { type: 'STAGE_COMPLETE'; payload: string }
  | { type: 'ADD_BOOKMARK'; payload: number }
  | { type: 'UPDATE_PROGRESS'; payload: Partial<UserProgress> }
  | { type: 'SET_ERROR'; payload: string }
  | { type: 'CLEAR_ERROR' };